home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / system / solaris / local / lastx.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  6KB  |  218 lines

  1. /*
  2.      Lastx v1.0    Written by Ryan Wyler  (ryanw@goodnet.com)
  3.  
  4.     
  5. Decription:
  6.  
  7.     A 'last' type utility for Solaris which displays the full information
  8. for the users.
  9.  
  10. Why:
  11.  
  12.     The version of Solaris which I run here (Solaris 2.5 Sparc) does not
  13. log the whole IP of the users in the file that 'last' uses to display the
  14. information (/var/adm/tmpx).  But it does store the full IP in the
  15. /var/adm/wtmpx file.  So this program helps me to findout where people are
  16. logging in from A LOT easier.  
  17.  
  18. Disclamer:
  19.  
  20.     If this breaks something.. don't come crying to me.. I'm not
  21.     responsable for nutin.. 
  22.  
  23.  
  24. Distibution:
  25.  
  26.      Feel Free to distribute this to whom ever can make use of this util.
  27.      It has helped me out a ton. :)
  28.  
  29.      I have not added in any comments due to lack of time.  Sorry.
  30.      I welcome comments/Suggestions to make it better if you care to send
  31.      any.  Otherwise, use at will.
  32.  
  33. */
  34.  
  35. #include <stdio.h>
  36. #include <utmpx.h>
  37. #include <sys/types.h>
  38. #include <fcntl.h>
  39. #define WTMP "/var/adm/wtmpx"
  40. #define UTMP "/var/adm/utmpx"
  41.  
  42. void nl()
  43. {
  44.   printf("\n");
  45. }
  46.  
  47. void main(argc,argv)
  48. int argc;
  49. char *argv[];
  50. {
  51.   struct utmpx utmp_ent;
  52.   char *date="",*ch,user;
  53.   int f,count=0,all=0,debug=0,x=1,success=0,other_file=0,help=0,done=0;
  54.  
  55.   nl();
  56.   printf(" Lastx v1.0    Written by Ryan Wyler (ryanw@goodnet.com)");
  57.   nl();
  58.   nl();
  59.   if(argc>1)
  60.     if(strcmp(argv[1],"-h")==0)
  61.       {
  62.         help=1;
  63.         done=1;
  64.       }
  65.   if((argc > 1)&&(!done))
  66.     {
  67.       do
  68.         {
  69.           if(strcmp(argv[x],"-a")==0)
  70.             all=1;
  71.           else
  72.             if(strcmp(argv[x],"-d")==0)
  73.               debug=1;
  74.             else
  75.               if(strcmp(argv[x],"-f")==0)
  76.                 {
  77.                   other_file=1;
  78.                   if(argc>x+1)
  79.                     {
  80.                       x++;
  81.                       if((f=open(argv[x],O_RDWR))>=0)
  82.                         success=1;
  83.                       else
  84.                         printf("  Error:  Check filename/path for '%s'\n\n",argv[x]);
  85.                     }
  86.                   else
  87.                     printf("  Error:  -f specified, but no filename followed -f\n\nexiting...\n");
  88.                 }
  89.               else
  90.                 strcpy(&user,argv[x]);
  91.           x++;
  92.         }
  93.       while(x < argc);
  94.     }
  95.   if((argc > 1)&&(!done))
  96.     {
  97.       if(all==1)
  98.         {
  99.           if(other_file==0)
  100.             if((f=open(WTMP,O_RDWR))>=0)
  101.               success=1;
  102.             else
  103.               printf("  Error:  Check filename/path:  %s\n\n",WTMP);
  104.           if(success==1)
  105.             {
  106.               while(read(f,&utmp_ent,sizeof(utmp_ent)))
  107.                 if(strncmp(utmp_ent.ut_user,".",1)!=0)
  108.                   {
  109.                     if(count==0)
  110.                       printf("  User        IP Address         (to see time specify specific user)\n");
  111.                     printf("  %s  %s\n",utmp_ent.ut_user,utmp_ent.ut_host);
  112.                     count++;
  113.                   }
  114.               nl();
  115.               printf("There were %i records listed",count);
  116.               nl();
  117.               close(f);
  118.             }
  119.         }
  120.       else
  121.         {
  122.           if(debug==1)
  123.             {
  124.               if(other_file==0)
  125.                 if((f=open(WTMP,O_RDWR))>=0)
  126.                   success=1;
  127.                 else
  128.                   printf("  Error:  Check filename/path:  %s\n\n",WTMP);
  129.               if(success==1)
  130.                 {
  131.                   while(read(f,&utmp_ent,sizeof(utmp_ent)))
  132.                     {
  133.                       if(count==0)
  134.                         printf("  User        IP Address         (to see time specify specific user)\n");
  135.                       printf("  %s  %s\n",utmp_ent.ut_user,utmp_ent.ut_host);
  136.                       count++;
  137.                     }
  138.                   nl();
  139.                   printf("There were %i records listed",count);
  140.                   nl();
  141.                   close(f);
  142.                 }
  143.             }
  144.           else
  145.             {
  146.               if(other_file==0)
  147.                 if((f=open(WTMP,O_RDWR))>=0)
  148.                   success=1;
  149.                 else
  150.                   printf("  Error:  Check filename/path:  %s\n\n",WTMP);
  151.               if(success==1)
  152.                 {
  153.                   while(read(f,&utmp_ent,sizeof(utmp_ent)))
  154.                     if(!strcmp(utmp_ent.ut_name, &user))
  155.                       {
  156.                         if(count==0)
  157.                           printf("  User        IP Address             Time\n");
  158.                         date = ctime(&utmp_ent.ut_xtime);
  159.                         date[strlen(date)-1] = '\0';
  160.                         printf("  %s  %s  %s\n",utmp_ent.ut_user,utmp_ent.ut_host,date);
  161.                         count++;
  162.                       }
  163.                   nl();
  164.                   printf("There were %i records listed",count);
  165.                   nl();
  166.                   close(f);
  167.                 }
  168.             }
  169.         }
  170.     }
  171.   else
  172.     {
  173.       printf("   Usage: %s <-h | -a | -d | [username]> <-f [filename]>",argv[0]);
  174.       nl();
  175.       printf(" Options:  -a     Display all users");
  176.       nl();
  177.       printf("           -d     Display all Entrys");
  178.       nl();
  179.       printf("           user   Displays entries for only that user");
  180.       nl();
  181.       printf("           -f     Specify a specific wtmpx file to use");
  182.       nl();
  183.       printf("           -h     Extended help (examples) %i",help);
  184.       nl();
  185.       nl();
  186.       if(help==1)
  187.         {
  188.           printf(" Examples:");
  189.           nl();
  190.           printf("   %s ryanw",argv[0]);
  191.           nl();
  192.           printf("     Shows all logins for ryanw");
  193.           nl();
  194.           nl();
  195.           printf("   %s -a",argv[0]);
  196.           nl();
  197.           printf("     Shows all records in wtmpx file");
  198.           nl();
  199.           nl();
  200.           printf("   %s -d",argv[0]);
  201.           nl();
  202.           printf("     Shows even MORE records in wtmpx file");
  203.           nl();
  204.           nl();
  205.           printf("   %s -f /var/adm/backup/wtmp.1 ryanw",argv[0]);
  206.           nl();
  207.           printf("     Shows all logins of user ryanw in file /var/adm/backup/wtmp.1");
  208.           nl();
  209.           nl();
  210.           printf("   %s -a -f <filename>",argv[0]);
  211.           nl();
  212.           printf("     Shows all records in <filename>");
  213.           nl();
  214.         }
  215.     }
  216.   exit(0);
  217. }
  218. /*                    www.hack.co.za              [2000]*/